package book;

import java.util.Arrays;

public class BookList {
    public Book[] books = new Book[10];
    public int usedSize;

    public BookList() {
        books[0] = new Book("三国演义","罗贯中",89,"小说");
        books[1] = new Book("西游记","吴承恩",78,"小说");
        books[2] = new Book("红楼梦","曹雪芹",49,"小说");
        this.usedSize = 3;
    }
    public Book getPos(int pos){
        return books[pos];
    }

    public void disPlay(){
        for (int i = 0; i < usedSize; i++) {
            Book book  = books[i];
            System.out.println(book);
        }
    }
    public void add(Book book){
        books[usedSize] = book;
        usedSize++;
    }
    public void del(String name){
        Book[] temp = new Book[10];
        int j = 0;
        for (int i = 0; i < usedSize; i++) {
            Book book = books[i];
            if(name.equals(book.getName())){
                continue;
            }else {
                temp[j] = books[i];
                j++;
            }
        }
        books = temp;
        usedSize--;
    }
}
